home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWRefCnt / FWSOMPtr.tpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.4 KB  |  240 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSOMPtr.tpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSOMPTR_H
  11. #include "FWSOMPtr.h"
  12. #endif
  13.  
  14. #ifndef FWSOMENV_H
  15. #include "FWSOMEnv.h"
  16. #endif
  17.  
  18.  
  19. //----------------------------------------------------------------------------------------
  20. //    FW_TSOMPtr<TRep>::FW_TSOMPtr
  21. //----------------------------------------------------------------------------------------
  22.  
  23. template<class TRep>
  24. FW_TSOMPtr<TRep>::FW_TSOMPtr() :
  25.     fRep(NULL)
  26. {
  27.     FW_END_CONSTRUCTOR
  28. }
  29.  
  30. //----------------------------------------------------------------------------------------
  31. //    FW_TSOMPtr<TRep>::~FW_TSOMPtr
  32. //----------------------------------------------------------------------------------------
  33.  
  34. template<class TRep>
  35. FW_TSOMPtr<TRep>::~FW_TSOMPtr()
  36. {
  37.     FW_START_DESTRUCTOR
  38.     delete fRep;
  39. }
  40.  
  41. //----------------------------------------------------------------------------------------
  42. //    FW_TSOMPtr<TRep>::FW_TSOMPtr
  43. //----------------------------------------------------------------------------------------
  44.  
  45. template<class TRep>
  46. FW_TSOMPtr<TRep>::FW_TSOMPtr(Environment *ev, TRep* rep) :
  47.     fRep(NULL)
  48. {
  49.     SetRep(ev, rep);
  50.     FW_END_CONSTRUCTOR
  51. }
  52.  
  53. //----------------------------------------------------------------------------------------
  54. //    FW_TSOMPtr<TRep>::SetRep
  55. //----------------------------------------------------------------------------------------
  56.  
  57. template<class TRep>
  58. void FW_TSOMPtr<TRep>::SetRep(Environment *, TRep* rep)
  59. {
  60.     if (fRep != rep)
  61.     {
  62.         delete fRep;
  63.         fRep = rep;
  64.     }
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //    FW_TSOMPtr<TRep>::operator new
  69. //----------------------------------------------------------------------------------------
  70.  
  71. // [JEL]
  72. // This method is private, and I'd prefer to leave it undefined, but CodeWarrior seems
  73. // to complain when instantiating templates with undefined methods, even if the methods
  74. // aren't used.
  75.  
  76. #ifndef __MRC__
  77. #if __MWERKS__ < 0x0800
  78.  
  79. template<class TRep>
  80. void* FW_TSOMPtr<TRep>::operator new(size_t size)
  81. {
  82.     FW_PRIV_ASSERT(false);
  83.     return 0;
  84. }
  85.  
  86. #endif
  87. #endif
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    FW_TSOMPtr<TRep>::FW_TSOMPtr(const FW_TSOMPtr<TRep>& other)
  91. //----------------------------------------------------------------------------------------
  92.  
  93. template<class TRep>
  94. FW_TSOMPtr<TRep>::FW_TSOMPtr(const FW_TSOMPtr<TRep>&)
  95. {
  96.     // [jkp] MetroWerks wants this to be defined
  97.     FW_PRIV_ASSERT(false);
  98. }
  99.  
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    FW_TSOMPtr<TRep>::operator=(const FW_TSOMPtr<TRep>& other)
  103. //----------------------------------------------------------------------------------------
  104.  
  105. template<class TRep>
  106. void FW_TSOMPtr<TRep>::operator=(const FW_TSOMPtr<TRep>&)
  107. {
  108.     // [jkp] MetroWerks wants this to be defined
  109.     FW_PRIV_ASSERT(false);
  110. }
  111.  
  112.  
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  116. //----------------------------------------------------------------------------------------
  117.  
  118. template<class TRep>
  119. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr() :
  120.     fRep(NULL)
  121. {
  122.     FW_END_CONSTRUCTOR
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    FW_TCountedSOMPtr<TRep>::~FW_TCountedSOMPtr
  127. //----------------------------------------------------------------------------------------
  128.  
  129. template<class TRep>
  130. FW_TCountedSOMPtr<TRep>::~FW_TCountedSOMPtr()
  131. {
  132.     FW_START_DESTRUCTOR
  133.     if (fRep != NULL)
  134.     {
  135.         FW_SOMEnvironment ev;
  136.  
  137.         if (fRep->Release(ev) == 0)
  138.             delete fRep;
  139.     }
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  144. //----------------------------------------------------------------------------------------
  145.  
  146. template<class TRep>
  147. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr(const FW_TCountedSOMPtr<TRep>& other) :
  148.     fRep(other.fRep)
  149. {
  150.     if (fRep != NULL)
  151.     {
  152.         FW_SOMEnvironment ev;
  153.  
  154.         fRep->Acquire(ev);
  155.     }
  156.  
  157.     FW_END_CONSTRUCTOR
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  162. //----------------------------------------------------------------------------------------
  163.  
  164. template<class TRep>
  165. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr(Environment *ev, const FW_TCountedSOMPtr<TRep>& other) :
  166.     fRep(other.fRep)
  167. {
  168.     if (fRep != NULL)
  169.         fRep->Acquire(ev);
  170.  
  171.     FW_END_CONSTRUCTOR
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  176. //----------------------------------------------------------------------------------------
  177.  
  178. template<class TRep>
  179. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr(Environment *ev, TRep* rep) :
  180.     fRep(rep)
  181. {
  182.     if (fRep != NULL)
  183.         fRep->Acquire(ev);
  184.  
  185.     FW_END_CONSTRUCTOR
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_TCountedSOMPtr<TRep>::operator=
  190. //----------------------------------------------------------------------------------------
  191.  
  192. template<class TRep>
  193. void FW_TCountedSOMPtr<TRep>::operator=(TRep* rep)
  194. {
  195.     FW_SOMEnvironment ev;
  196.     SetRep(ev, rep);
  197. }
  198.  
  199. //----------------------------------------------------------------------------------------
  200. //    FW_TCountedSOMPtr<TRep>::SetRep
  201. //----------------------------------------------------------------------------------------
  202.  
  203. template<class TRep>
  204. void FW_TCountedSOMPtr<TRep>::SetRep(Environment *ev, TRep* rep)
  205. {
  206.     if (fRep != rep)
  207.     {
  208.         if (fRep != NULL && fRep->Release(ev) == 0)
  209.             delete fRep;
  210.  
  211.         fRep = rep;
  212.         
  213.         if (fRep != NULL)
  214.             fRep->Acquire(ev);
  215.     }
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_TCountedSOMPtr<TRep>::operator new
  220. //----------------------------------------------------------------------------------------
  221.  
  222. // [JEL]
  223. // This method is private, and I'd prefer to leave it undefined, but CodeWarrior seems
  224. // to complain when instantiating templates with undefined methods, even if the methods
  225. // aren't used.
  226.  
  227. #ifndef __MRC__
  228. #if __MWERKS__ < 0x0800
  229.  
  230. template<class TRep>
  231. void* FW_TCountedSOMPtr<TRep>::operator new(size_t size)
  232. {
  233.     FW_PRIV_ASSERT(false);
  234.     return 0;
  235. }
  236.  
  237. #endif 
  238. #endif 
  239.  
  240.